package com.rabbiter.oes.controller;

import com.rabbiter.oes.entity.ApiResult;
import com.rabbiter.oes.util.AllOssUtil;
import com.rabbiter.oes.util.ApiResultHandler;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

@RestController
public class FileUploadCpntroller {
    @PostMapping("/upload")
    public ApiResult upload(MultipartFile file) throws Exception {
        String filename = file.getOriginalFilename();
        filename = UUID.randomUUID().toString() + filename.substring(filename.lastIndexOf("."));
        String url =  AllOssUtil.uoloadFile(filename,file.getInputStream());
        return ApiResultHandler.success(url);
    }
}
